package source;


import java.awt.Dimension;
import java.text.DecimalFormat;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JTextField;



/**
 * @author Dancob-PC
 *
 */
public class CalculadoraInterfaz {

	private static  DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" );  //  @jve:decl-index=0:

	private JFrame jFrame1 = null;  //  @jve:decl-index=0:visual-constraint="328,23"
	private JPanel jContentPane = null;

	private JButton jButton = null;

	private JButton jButton1 = null;
	private int seleccionado = 1;
	private JButton jButton2 = null;

	private JButton jButton3 = null;

	private JButton jButton4 = null;

	private JLabel jLabel = null;

	private JTextField jTextField = null;

	private JTextField jTextField1 = null;

	private JTextField jTextField2 = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JButton jButton5 = null;

	private JButton jButton6 = null;

	private JButton jButton61 = null;

	private JButton jButton51 = null;

	private JButton jButton52 = null;

	private JButton jButton53 = null;

	private JButton jButton54 = null;

	private JButton jButton55 = null;

	private JButton jButton56 = null;

	private JButton jButton57 = null;

	/**
	 * This method initializes jFrame1	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	private JFrame getJFrame1() {
		if (jFrame1 == null) {
			jFrame1 = new JFrame();
			jFrame1.setSize(new Dimension(350, 526));
			jFrame1.setContentPane(getJContentPane());
			jFrame1.setTitle("Calculadora");
		}
		return jFrame1;
	}

	/**
	 * This method initializes jContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(252, 16, 23, 16));
			jLabel2.setText("Y:");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(75, 17, 26, 16));
			jLabel1.setText("X:");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(135, 93, 73, 16));
			jLabel.setText("Respuesta:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJButton1(), null);
			jContentPane.add(getJButton2(), null);
			jContentPane.add(getJButton3(), null);
			jContentPane.add(getJButton4(), null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(getJTextField1(), null);
			jContentPane.add(getJTextField2(), null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(getJButton5(), null);
			jContentPane.add(getJButton6(), null);
			jContentPane.add(getJButton61(), null);
			jContentPane.add(getJButton51(), null);
			jContentPane.add(getJButton52(), null);
			jContentPane.add(getJButton53(), null);
			jContentPane.add(getJButton54(), null);
			jContentPane.add(getJButton55(), null);
			jContentPane.add(getJButton56(), null);
			jContentPane.add(getJButton57(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(14, 178, 53, 44));
			jButton.setText("+");
			jButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					System.out.println("mouseClicked()"); // TODO Auto-generated Event stub mouseClicked()
				}
			});
			jButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					try{
						jTextField.setText(Sumar(Double.parseDouble(jTextField1.getText()), Double.parseDouble(jTextField2.getText())));
						
					}
					catch (Exception e1) {
						// TODO: handle exception
						jTextField.setText("Operacion Incorrecta");
					} 
					
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(75, 178, 50, 45));
			jButton1.setText("-");
			jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					try{
						jTextField.setText(Restar(Double.parseDouble(jTextField1.getText()), Double.parseDouble(jTextField2.getText())));
						
					}
					catch (Exception e1) {
						// TODO: handle exception
						jTextField.setText("Operacion Incorrecta");
					} 
				}
			});
		}
		return jButton1;
	}

	/**
	 * This method initializes jButton2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setBounds(new Rectangle(135, 179, 49, 44));
			jButton2.setText("x");
			jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					try{
						jTextField.setText(Multiplicar(Double.parseDouble(jTextField1.getText()), Double.parseDouble(jTextField2.getText())));
						
					}
					catch (Exception e1) {
						// TODO: handle exception
						jTextField.setText("Operacion Incorrecta");
					} 
				}
			});
		}
		return jButton2;
	}

	/**
	 * This method initializes jButton3	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton3() {
		if (jButton3 == null) {
			jButton3 = new JButton();
			jButton3.setBounds(new Rectangle(195, 178, 49, 45));
			jButton3.setText("/");
			jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					try{
						jTextField.setText(Dividir(Double.parseDouble(jTextField1.getText()), Double.parseDouble(jTextField2.getText())));
						
					}
					catch (Exception e1) {
						// TODO: handle exception
						jTextField.setText("Operacion Incorrecta");
					} 
				}
			});
		}
		return jButton3;
	}

	/**
	 * This method initializes jButton4	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton4() {
		if (jButton4 == null) {
			jButton4 = new JButton();
			jButton4.setBounds(new Rectangle(255, 180, 60, 42));
			jButton4.setText("mod");
			jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					try{
						jTextField.setText(Modulo(Double.parseDouble(jTextField1.getText()), Double.parseDouble(jTextField2.getText())));
						
					}
					catch (Exception e1) {
						// TODO: handle exception
						jTextField.setText("Operacion Incorrecta");
					} 
				}
			});
		}
		return jButton4;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(16, 117, 298, 52));
		}
		return jTextField;
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new Rectangle(14, 44, 134, 40));
			jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
				

				public void mouseClicked(java.awt.event.MouseEvent e) {
					seleccionado  = 1;
				}
			});
		}
		return jTextField1;
	}

	/**
	 * This method initializes jTextField2	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
			jTextField2.setBounds(new Rectangle(191, 44, 125, 40));
			jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					seleccionado = 2;
				}
			});
		}
		return jTextField2;
	}

	/**
	 * This method initializes jButton5	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton5() {
		if (jButton5 == null) {
			jButton5 = new JButton();
			jButton5.setBounds(new Rectangle(16, 235, 89, 49));
			jButton5.setText("7");
			jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"7");
					else jTextField2.setText(jTextField2.getText()+"7");
				}
			});
		}
		return jButton5;
	}

	/**
	 * This method initializes jButton6	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton6() {
		if (jButton6 == null) {
			jButton6 = new JButton();
			jButton6.setBounds(new Rectangle(120, 235, 91, 51));
			jButton6.setText("8");
			jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"8");
					else jTextField2.setText(jTextField2.getText()+"8");
				}
			});
		}
		return jButton6;
	}

	/**
	 * This method initializes jButton61	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton61() {
		if (jButton61 == null) {
			jButton61 = new JButton();
			jButton61.setBounds(new Rectangle(225, 235, 92, 50));
			jButton61.setText("9");
			jButton61.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"9");
					else jTextField2.setText(jTextField2.getText()+"9");
				}
			});
		}
		return jButton61;
	}

	/**
	 * This method initializes jButton51	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton51() {
		if (jButton51 == null) {
			jButton51 = new JButton();
			jButton51.setBounds(new Rectangle(16, 300, 90, 49));
			jButton51.setText("4");
			jButton51.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"4");
					else jTextField2.setText(jTextField2.getText()+"4");
				}
			});
		}
		return jButton51;
	}

	/**
	 * This method initializes jButton52	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton52() {
		if (jButton52 == null) {
			jButton52 = new JButton();
			jButton52.setBounds(new Rectangle(121, 299, 91, 48));
			jButton52.setText("5");
			jButton52.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"5");
					else jTextField2.setText(jTextField2.getText()+"5");
				}
			});
		}
		return jButton52;
	}

	/**
	 * This method initializes jButton53	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton53() {
		if (jButton53 == null) {
			jButton53 = new JButton();
			jButton53.setBounds(new Rectangle(225, 300, 91, 50));
			jButton53.setText("6");
			jButton53.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"6");
					else jTextField2.setText(jTextField2.getText()+"6");
				}
			});
		}
		return jButton53;
	}

	/**
	 * This method initializes jButton54	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton54() {
		if (jButton54 == null) {
			jButton54 = new JButton();
			jButton54.setBounds(new Rectangle(15, 361, 91, 51));
			jButton54.setText("1");
			jButton54.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"1");
					else jTextField2.setText(jTextField2.getText()+"1");
				}
			});
		}
		return jButton54;
	}

	/**
	 * This method initializes jButton55	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton55() {
		if (jButton55 == null) {
			jButton55 = new JButton();
			jButton55.setBounds(new Rectangle(120, 361, 91, 51));
			jButton55.setText("2");
			jButton55.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"2");
					else jTextField2.setText(jTextField2.getText()+"2");
				}
			});
		}
		return jButton55;
	}

	/**
	 * This method initializes jButton56	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton56() {
		if (jButton56 == null) {
			jButton56 = new JButton();
			jButton56.setBounds(new Rectangle(224, 362, 91, 49));
			jButton56.setText("3");
			jButton56.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"3");
					else jTextField2.setText(jTextField2.getText()+"3");
				}
			});
		}
		return jButton56;
	}

	/**
	 * This method initializes jButton57	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton57() {
		if (jButton57 == null) {
			jButton57 = new JButton();
			jButton57.setBounds(new Rectangle(15, 422, 301, 44));
			jButton57.setText("0");
			jButton57.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					if(seleccionado == 1) jTextField1.setText(jTextField1.getText()+"0");
					else jTextField2.setText(jTextField2.getText()+"0");
				}
			});
		}
		return jButton57;
	}

	/**
	 * Metodo para inicializar la aplicacion.
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		  CalculadoraInterfaz iec = new CalculadoraInterfaz();
		  iec.getJFrame1().setVisible(true );
		
	}
	/**
	 * 
	 * @param i Numero 1.
	 * @param j Numero 2.
	 * @return  Suma de los dos numeros.
	 */
	public String Sumar(double i, double j) {
		// TODO Auto-generated method stub
		return df2.format(i+j)+"";
	}
	/**
	 * 
	 * @param i Numero 1.
	 * @param j Numero 2.
	 * @return  Multiplicacion de los dos numeros.
	 */
	public String Multiplicar(double i, double j) {
		// TODO Auto-generated method stub
		return df2.format(i*j)+"";
	}
	/**
	 * 
	 * @param i Numero 1.
	 * @param j Numero 2.
	 * @return  Resta de los dos numeros.
	 */
	public String Restar(double i, double j) {
		// TODO Auto-generated method stub
	
		return df2.format(i-j)+"";
	}
	/**
	 * 
	 * @param i Numero 1.
	 * @param j Numero 2.
	 * @return  Division de los dos numeros.
	 */
	public String Dividir(double i, double j) {
		// TODO Auto-generated method stub
	
		return df2.format(i/j)+"";
	
	}
	/**
	 * 
	 * @param i Numero 1.
	 * @param j Numero 2.
	 * @return  Modulo de los dos numeros.
	 */
	public String Modulo(double i, double j) {
		// TODO Auto-generated method stub
	
		return df2.format(i%j)+"";
	
	}
}
